import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#从fbprophet库中导入Prophet类
from fbprophet import Prophet

data = pd.read_csv('./py01/PythonApp01/data/monthly-car-sales.csv',header=0)
data['Month'] = pd.to_datetime(data['Month'], format='%Y-%m')
data['Sales'] = pd.to_numeric(data['Sales'])
#预处理数据，把Month列改名为ds，Sales列改名为y
data = data.rename(columns = {"Month":"ds", "Sales":"y"})[["ds","y"]]

model = Prophet(yearly_seasonality=True, weekly_seasonality=True, daily_seasonality=True)
model.add_country_holidays(country_name="USA")
#拟合数据
model.fit(data)

#设置未来时间点
#future = model.make_future_dataframe(periods=365)
future = model.make_future_dataframe(periods=12,freq='M',include_history=False)
#预测
forecast = model.predict(future)
print(forecast.tail())
fig = model.plot(forecast)